﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Ras2Logic;

namespace Ras2Win
{
    /// <summary>
    /// Klasinn EditPerformer
    /// </summary>
    public partial class EditPerformer : Form
    {
        #region Member Breytur

        /// <summary>
        /// Memberbreyta sem inniheldur einn performer.
        /// </summary>
        private Performer m_performer;

        #endregion

        #region Smiðir

        /// <summary>
        /// Færibreytulaus smiður.
        /// </summary>
        public EditPerformer()
        {
            InitializeComponent();
        }

        #endregion

        #region Get / Set föll

        /// <summary>
        /// GetSet fall fyrir breytuna Performer sem er af taginu Performer.
        /// </summary>
        public Performer Performer
        {
            get
            {
                m_performer.ID = Convert.ToInt32(m_txtPerformerID.Text);
                m_performer.Name = m_txtPerformerName.Text;
                m_performer.Description = m_txtPerformerDescription.Text;
                m_performer.Url = m_PerformerUrl.Text;
                m_performer.Image = m_txtPerformerImage.Text;
                return m_performer;
            }
            set
            {
                m_performer = value;
                m_txtPerformerID.Text = Convert.ToString(m_performer.ID);
                m_txtPerformerName.Text = m_performer.Name;
                m_txtPerformerDescription.Text = m_performer.Description;
                m_PerformerUrl.Text = m_performer.Url;
                m_txtPerformerImage.Text = m_performer.Image;
            }
        }

        #endregion

        #region Private föll

        /// <summary>
        /// EditPerfomer_load keyrir þegar edit glugginn er smíðaður.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void EditPerformer_Load(object sender, EventArgs e)
        {
            //Ef mynd þá birtum við hana.
            if (m_txtPerformerImage.Text != "")
            {
                try
                {
                    m_picboxPerformer.ImageLocation = ".\\" + m_txtPerformerImage.Text;
                    m_picboxPerformer.SizeMode = PictureBoxSizeMode.StretchImage;
                    m_picboxPerformer.Load();
                }
                catch (Exception)
                {
                    DefaultPicture();
                }
            }
            else
            {
                DefaultPicture();
                
            }
        }

        /// <summary>
        /// Hjálparfall sem birtir default mynd ef mynd á performer finnst ekki.
        /// Ef default mynd finnst ekki þá er engin mynd birt.
        /// </summary>
        private void DefaultPicture()
        {
            try
            {
                m_picboxPerformer.ImageLocation = ".\\default.jpg";
                m_picboxPerformer.SizeMode = PictureBoxSizeMode.StretchImage;
                m_picboxPerformer.Load();
            }
            catch (Exception)
            {
            }
        }

        /// <summary>
        /// Fall sem sækir slóð á mynd, setur slóðina í texta gluggann og birtir myndina.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_btnPerformerGetImage_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                m_txtPerformerImage.Text = openFile.SafeFileName;

                try
                {
                    m_picboxPerformer.ImageLocation = ".\\" + m_txtPerformerImage.Text;
                    m_picboxPerformer.SizeMode = PictureBoxSizeMode.StretchImage;
                    m_picboxPerformer.Load();
                }
                catch (Exception)
                {
                    DefaultPicture();
                }
            }
        }

        #endregion

        #region Public föll

        #endregion
    }
}
